package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.query.SaleChartObjectQuery;
import cn.wolfcode.crm.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class IndexController {
    @Autowired
    private ISignService signService;
    @Autowired
    private IInsurancebillService iInsurancebillService;
    @Autowired
    private IClientService clientService;
    @Autowired
    private IClaimresultService claimresultService;
    @Autowired
    private ISaleAccountService saleAccountService;


    @RequestMapping("index")
    public String login(Model model) {
        //容器
        Map<String, Object> baba = new HashMap<>();

        //签到
        int signState = signService.getStateByEmployee();
        //添加
        baba.put("signState", signState);

        //销售总额
        BigDecimal billAccount = iInsurancebillService.selectBillAccount();

        baba.put("billAccount", billAccount);


        //model
        model.addAttribute("baba", baba);

        return "index";
    }


    @RequestMapping("allIndex")
    public String index(Model model) {
        //容器
        Map<String, Object> babaT = new HashMap<>();


        //销售总额
        BigDecimal billAccount = iInsurancebillService.selectBillAccount();

        babaT.put("billAccount", billAccount);

        //总客户数
        int clientAccount=clientService.selectClientAccount();
        babaT.put("clientAccount",clientAccount);

        //完成理赔单数
        int claimresultAccount=claimresultService.selectClaimResultAccount();
        babaT.put("claimresultAccount",claimresultAccount);

        //资源池客户数
        int dClientAccount=clientService.selectDClientAccount();
        babaT.put("dClientAccount",dClientAccount);

        //销售排序
        SaleChartObjectQuery saleChartObjectQuery =new SaleChartObjectQuery();
        saleChartObjectQuery.setGroupType("e.username");

        List<Map<String, Object>> maps = saleAccountService.selectAllToIndex(saleChartObjectQuery);
        babaT.put("maps",maps);

        //model
        model.addAttribute("babaT", babaT);


        return "allindex";
    }


}
